cmake_minimum_required(VERSION 3.5)
cmake_policy(VERSION 3.0)

project(GPU-perf-cuda)

set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
EXECUTE_PROCESS( COMMAND uname -m
                 COMMAND tr -d '/r/n'
                 OUTPUT_VARIABLE ARCHITECTURE )
message( -- " " STATUS " Architecture: " ${ARCHITECTURE} )
if ( ${ARCHITECTURE} MATCHES "X86|x86" )
    message( -- " " STATUS " Machine is X86 Architecture" )
else()
    LINK_DIRECTORIES( /usr/local/lib )
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/libary)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/)

include_directories(include)

if( "$ENV{GPU_PLATFORM}" STREQUAL "MTGPU" )
    message(STATUS "using MT GPU")
    list(APPEND CMAKE_MODULE_PATH /usr/local/musa/cmake)
    find_package(MUSA REQUIRED)
    set(CUDA_INCLUDE_DIRS ${MUSA_INCLUDE_DIRS})
    set(CUDA_LIBRARIES ${MUSA_LIBRARIES})
    set(MATH_LIBRARIES ${MUSA_MUFFT_LIBRARIES} ${MUSA_MUBLAS_LIBRARIES})
    execute_process(COMMAND bash ./media/cuda2musa.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
    message(STATUS "using NV GPU")
    find_package(CUDA REQUIRED)
    set(MATH_LIBRARIES ${CUDA_CUFFT_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES})
endif()

add_library(
     cuda-framwork
     thirdparty/cucheck.cpp
     thirdparty/cudeviceinfo.cpp
     thirdparty/cuevent.cpp
)
target_include_directories(cuda-framwork PRIVATE ${CUDA_INCLUDE_DIRS})
target_link_libraries(cuda-framwork ${CUDA_LIBRARIES})

add_library(
     common
     thirdparty/node.cpp
     thirdparty/log.cpp
     thirdparty/stopwatch.cpp
     thirdparty/score.cpp
)

set(target_name
    ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/log
    ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}output
)

add_custom_target(custom-directory ALL
    COMMAND ${CMAKE_COMMAND} -E make_directory ${target_name})

add_subdirectory(example)


